$(document).ready(function(){
    //该形式只能应用在form表单中
    $("#registerform").validate({
        rules:{
            u_name:{
                required:true,
                minlength:3
            },
            u_psd:{
                required: true,
                minlength: 6
            },
            u_psd1:{
                required: true,
                minlength: 6,
                equalTo:"[name='u_psd']"
            }
        },
        messages:{
            u_name:{
                required:"用户名不能为空！",
                minlength:"用户名不能少于3位！"
            },
            u_psd:{
                required: "密码不能为空！",
                minlength: "密码不能少于6位！",
            },
            u_psd1:{
                required: "确认密码不能为空",
                minlength: "确认密码不能少于6位",
                equalTo:"确认密码不一致"
            }
        }
    });
    $("#u_name").blur(function () {
        $.ajax({
            url:"user/CheckUserNameExits",
            type:"post",
            dataType:"json",
            data:{
                u_name:$("#u_name").val(),
            },
            //result封装成立json对象，解析result.
            success:function (result) {
                var errorCode = result.errorCode;
                // alert(JSON.stringify(result));
                if(errorCode==-1){
                    var msg = result.status;
                    $("#errorLog").text(msg);
                    $("#errorLog").removeClass("hidden");
                    $("#u_name").val("");
                }else if(errorCode==0){
                    $("#errorLog").addClass("hidden");
                }
            },
            error:function (result) {

            }
        })
    });
    $("#u_psd1").blur(function () {
        var psd= $("#u_psd").val();
        var psd1= $("#u_psd1").val();
        if(psd != psd1){
            $("#errorLog").text("两次密码输入不一致");
            $("#errorLog").removeClass("hidden");
        }else{
            $("#errorLog").addClass("hidden");
        }
    });
});